Skip to main content

ChartView

Lightweight chart module

ChartView is a lightweight version of the chart component, built for simple use cases that don't require advanced features or data providers. It offers a small API surface focused on updating chart settings and feeding custom or static data.

Use ChartView when you need to show a chart with your own data and control it in your code without the overhead of full data provider integration.

Basic concepts

  • ChartView: The main interface for a lightweight chart.
  • Settings API: Used to configure chart appearance and behavior.
  • Data Update API: Used to push custom or updated data into the chart.

API reference

Public properties

  • statePublisher: AnyPublisher<ChartView.State, Never>
    A Combine publisher that emits the chart's state (suspend, loading, isLoaded).

    Note: Use this publisher to detect when the chart reaches the isLoaded state. Call chart methods only after that. Calling API methods too early may result in no effect or errors.

Settings and appearance

  • setupSettings(_ settings: Chart.Settings, aggregation: Aggregation, instrument: Instrument)
    Configure the chart’s appearance and behavior, including watermark and timezone.
  • setupSettings(_ settings: Chart.Settings)
    Update chart settings without changing appearance or instrument.
  • setupColorTheme(_ theme: Chart.Theme)
    Apply a color theme to the chart.
  • setupVisibleTimeframe(start: Int64, end: Int64, disabledAnimation: Bool = false)
    Set the visible time range on the chart.
  • setupWatermarkVisibility(_ isVisible: Bool)
    Show or hide the watermark.
  • updateWatermark(firstRow: String, secondRow: String, thirdRow: String)
    Set or update watermark text (up to three lines).
  • updateTimezone(_ timezone: String)
    Set the chart timezone (e.g., "America/New_York").

Data management

  • setupCandles(_ candles: [Candle], for instrument: Instrument, completion: ((Error?) -> Void)? = nil)
    Initialize the chart with historical candle data.
  • updateCandles(_ candles: [Candle], completion: ((Error?) -> Void)? = nil)
    Add or refresh candle data.

Crosshair and highlights

  • setupCrosshairVisibility(_ isVisible: Bool)
    Show or hide the crosshair tool.
  • setupHighlightsVisibility(_ isVisible: Bool)
    Show or hide visual highlights such as session breaks.

News and events

  • setNews(_ news: [Chart.News])
    Display news items on the chart.
  • setupEvents(_ events: [Chart.Event])
    Display event items on the chart.

Example: Creating and using a ChartView

import DXChart
import UIKit
let chartView = ChartView()
// Wait for chart to be loaded before interacting
let cancellable = chartView.statePublisher.sink { state in
guard state == .isLoaded else { return }
// Update chart settings
var settings = Chart.Settings()
settings.selectedTheme = .light
chartView.setupSettings(settings, aggregation: .day, instrument: myInstrument)
// Update chart data
let data = [Candle(/* ... */)]
chartView.setupCandles(data, for: myInstrument)
// Update watermark
chartView.updateWatermark(firstRow: "AAPL", secondRow: "Apple Inc.", thirdRow: "30m")
}

Tips

  • Use ChartView when you need a simple chart integration with full control over data and settings.
  • No need to implement data providers.
  • To support indicators, drawings, instrument search, and other advanced features, use ChartScreen instead.